﻿using Engine;
using TemplatesDatabase;

namespace Game
{
    public class Yiliao : SubsystemBlockBehavior
    {
        public SubsystemAudio m_subsystemAudio;

        public Random m_random = new Random();

        public ComponentHealth componentHealth;

        public ComponentVitalStats componentVitalStats;

        public SubsystemTerrain m_subsystemTerrain;

        public ComponentSickness componentSickness;

        public ComponentFlu componentFlu;

        public float m_fluDuration;

        public float m_sicknessDuration;

        public override int[] HandledBlocks => new int[1] { 314 };

        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
        {
            m_subsystemAudio.PlaySound("Audio/Piston", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
            ComponentPlayer componentPlayer = componentMiner.ComponentPlayer;
            if (componentPlayer != null)
            {
                componentPlayer.ComponentHealth.Heal(1f);
                componentPlayer.ComponentVitalStats.Stamina = 1f;
                componentPlayer.ComponentSickness.m_sicknessDuration = 0f;
                componentPlayer.ComponentFlu.m_fluDuration = 0f;
                componentPlayer.ComponentGui.DisplaySmallMessage("身体得到了恢复", Color.White, blinking: true, playNotificationSound: true);
            }

            componentMiner.RemoveActiveTool(1);
            return true;
        }

        public override void Load(ValuesDictionary valuesDictionary)
        {
            base.Load(valuesDictionary);
            m_subsystemTerrain = base.Project.FindSubsystem<SubsystemTerrain>(throwOnError: true);
            m_subsystemAudio = base.Project.FindSubsystem<SubsystemAudio>(throwOnError: true);
        }
    }
}